home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / RoboSamSlot / CRecipientIterator.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  3.7 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CRecipientIterator.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     1/11/95    TMH        added IsLast()
  13.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  14.                  6/15/94    TMH        xxx put comment here xxx
  15.  
  16.     To Do:
  17. */
  18.  
  19. #ifndef __STRING__
  20. #include "String.h"
  21. #endif
  22.  
  23.  
  24. #ifndef __CRecipientIterator__
  25. #include "CRecipientIterator.h"
  26. #endif
  27.  
  28.  
  29. //-----------------------------------------
  30. //        C R e c i p i e n t I t e r a t o r
  31. //-----------------------------------------
  32.  
  33.  
  34.  
  35. //--------------------------------------------------------------------------
  36. CRecipientIterator::CRecipientIterator(MailMsgRef msgRef,MailAttributeID recipientKind)
  37. {
  38.     memset(fRecipientBuffer,0xBB,sizeof(kMaxRecipSize));    // test pattern. So we can see buffer in debugger
  39.     
  40.     short                fNumRecipientsReturned = 0;
  41.     short                fGetIndex = 0;
  42.         
  43.     fCurrentRecipientPtr = (OrigRecipient*)fRecipientBuffer;
  44.  
  45.     memset(&fPB,0,sizeof(MSAMGetRecipientsPB));
  46.     fPB.attrID = recipientKind;
  47.  
  48.     fPB.startIndex = 1;
  49.     fPB.more = true;
  50.     fPB.nextIndex = 1;
  51.     
  52.     fPB.mailMsgRef = msgRef;
  53.  
  54.     fPB.buffer.buffer = fRecipientBuffer;
  55.     fPB.buffer.bufferSize = kMaxRecipSize;
  56.     fPB.more = true;
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63. //--------------------------------------------------------------------------
  64. Boolean CRecipientIterator::More()
  65. {
  66.  
  67.     //    Advice.  Keep this small (its called alot)
  68.     //    More Advice.  Do NOT change any values here.
  69.     
  70.     if( fNumRecipientsReturned == 0)
  71.         return false;
  72.         
  73.     
  74.     if( fGetIndex  < fNumRecipientsReturned )
  75.         return true;
  76.     else 
  77.         return fPB.more;
  78.     
  79.  
  80. }
  81.  
  82.  
  83.  
  84. //--------------------------------------------------------------------------
  85. void CRecipientIterator::Advance()
  86. {
  87.     fGetIndex++;
  88.  
  89.     if( fGetIndex < fNumRecipientsReturned ) {
  90.  
  91.         unsigned long nextOffset = sizeof(MailOriginalRecipient) + sizeof(short) + fCurrentRecipientPtr->packedRecip.dataLength;
  92.         nextOffset += nextOffset&1;
  93.         fCurrentRecipientPtr =    (OrigRecipient*) ((char*)fCurrentRecipientPtr + nextOffset);
  94.         
  95.     } else {
  96.         if( fPB.more )
  97.             this->GetMore();
  98.     }
  99.     
  100.     return;
  101. }
  102.  
  103.  
  104. //--------------------------------------------------------------------------
  105. OrigRecipient* CRecipientIterator::FirstRecipient()
  106. {
  107.     fCurrentRecipientPtr = 0;
  108.     fNumRecipientsReturned = 0;
  109.     
  110.     fPB.startIndex = 1;
  111.     fPB.nextIndex = 1;
  112.     
  113.     this->GetMore();
  114.         
  115.     return fCurrentRecipientPtr;
  116. }
  117.  
  118.  
  119. //--------------------------------------------------------------------------
  120. OrigRecipient* CRecipientIterator::NextRecipient() 
  121. {
  122.     if( this->More() ) 
  123.         this->Advance();
  124.     else 
  125.         fCurrentRecipientPtr = 0; 
  126.         
  127.     return  fCurrentRecipientPtr;
  128. }
  129.  
  130.  
  131. //--------------------------------------------------------------------------
  132. void CRecipientIterator::GetMore() 
  133. {
  134.     fNumRecipientsReturned = 0;
  135.     fGetIndex = 0;
  136.     
  137.     fPB.startIndex = fPB.nextIndex;
  138.     OSErr osErr = MSAMGetRecipients((MSAMParam *)&fPB,false);
  139.     
  140.     if( osErr == 0 ) {
  141.         fNumRecipientsReturned = *(short*)fRecipientBuffer;
  142.         if( fNumRecipientsReturned != 0 )
  143.             fCurrentRecipientPtr = (OrigRecipient*) ((char*)fRecipientBuffer + sizeof(short));
  144.     }
  145.     
  146. }
  147.  
  148.  
  149.  
  150.  
  151. //-------------------------------------------------------------
  152. //        C R e s o l v e d R e c i p i e n t I t e r a t o r
  153. //------------------------------------------------------------
  154.  
  155.  
  156. //--------------------------------------------------------------------------
  157. void CResolvedRecipientIterator::Advance()
  158. {
  159.     fGetIndex++;
  160.  
  161.     if( fGetIndex < fNumRecipientsReturned ) {
  162.  
  163.         unsigned long nextOffset = sizeof(MailResolvedRecipient) + sizeof(short) + ((ResolvedRecipient*)fCurrentRecipientPtr)->packedRecip.dataLength;
  164.         nextOffset += nextOffset&1;
  165.         fCurrentRecipientPtr =    (OrigRecipient*) ((char*)fCurrentRecipientPtr + nextOffset);
  166.         
  167.     } else {
  168.         if( fPB.more )
  169.             this->GetMore();
  170.     }
  171.     
  172.     return;
  173. }
  174.  
  175.  
  176.  
  177.